﻿using Common.DataBase.Interface;
using Common.Utils;
using CommonUtils.Attributes;
using ScanFile.Dal;
using ScanFile.Model;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Windows.Forms;

namespace DALTest {
  public partial class Form1 : Form {
    public Form1() {
      InitializeComponent();
    }

    private Logger _logger = Logger.GetLogger(typeof(Form1));

    private DiskExDal diskExDal = new DiskExDal();

    private FileExDal fileExDal = new FileExDal();

    private FolderExDal folderExDal = new FolderExDal();


    private void button1_Click(object sender, EventArgs e) {
      List<DiskEx> list = new List<DiskEx>();
      DiskEx diskEx = new DiskEx() { };
      diskEx.Id = 1;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);

      diskEx = new DiskEx() { };
      diskEx.Id = 2;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);


      diskEx = new DiskEx() { };
      diskEx.Id = 3;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);


      diskEx = new DiskEx() { };
      diskEx.Id = 4;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);


      diskEx = new DiskEx() { };
      diskEx.Id = 5;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);

      diskEx = new DiskEx() { };
      diskEx.Id = 6;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;
      list.Add(diskEx);

      diskExDal.AddList(list);

      //diskExDal.Add(diskEx);




    }

    private void button2_Click(object sender, EventArgs e) {
      DiskEx diskEx = new DiskEx() { };
      diskEx.Id = DateTime.Now.Ticks;
      diskEx.DiskNumber = Guid.NewGuid().ToString();
      diskEx.DiskLabel = "C:";
      diskEx.DiskType = "Local";
      diskEx.ScanTime = DateTime.Now;//.ToString();
      diskEx.Enabled = 1;

     
      PropertyInfo[] propertys = typeof(DiskEx).GetProperties();
      foreach(PropertyInfo info in propertys) {
        Attribute[] atts = Attribute.GetCustomAttributes(info);
        foreach(Attribute att in atts) {
          if(att.GetType() == typeof(DBColumn)) {
            this.textBox1.AppendText(((DBColumn)att).ColumnName+"\r\n");
          }
        }
      }



      Object[] bookarr;//对象数组

      MemberInfo typeinfo = typeof(DiskEx);
      //调用GetCustomAttributes方法获取与BookAttribute类有关的属性列表，该方法返回一个对象数组
      bookarr = typeinfo.GetCustomAttributes(typeof(DBTable), false);
      if(bookarr.GetLength(0) != 0) {
        DBTable bookattribute1 = (DBTable)bookarr[0];//获取属性类的第一个成员
        this.Text = bookattribute1.TableName;
      }



    }

    private void button3_Click(object sender, EventArgs e) {
      DiskEx diskEx = new DiskEx() { };
      diskEx.Id = 1;



      diskEx = diskExDal.FindByPrimary(diskEx);

      this.Text = diskEx.DiskNumber;

      diskEx.Id = 2;
      diskExDal.DisableOnebyId(diskEx);
      //diskExDal.DeleteAllDisable();

      List<DiskEx> list = diskExDal.GetAll();

      MessageBox.Show(list.Count.ToString());
    }
  }
}
